Be sure to include --extern for dev-deps and examples
authorAlex Crichton <alex@alexcrichton.com>
Sun, 28 Dec 2014 09:04:10 +0000 (01:04 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Sun, 28 Dec 2014 09:04:10 +0000 (01:04 -0800)
src/cargo/ops/cargo_rustc/context.rs
tests/test_cargo_test.rs

index 70ce7f2637985ed20159de9fecf7b4e4c0db002d..8bcd5d720890a66d29b897773cbf8ebe1ccd9c5b 100644 (file)
@@ -284,9 +284,10 @@ impl<'a, 'b: 'a> Context<'a, 'b> {
                 target.get_profile().is_custom_build() == pkg_dep.is_build();
 
             // If this dependency is *not* a transitive dependency, then it
-            // only applies to test targets
+            // only applies to test/example targets
             let is_actual_dep = pkg_dep.is_transitive() ||
-                                target.get_profile().is_test();
+                                target.get_profile().is_test() ||
+                                target.is_example();
 
             is_correct_dep && is_actual_dep
         }).filter_map(|pkg| {
index 99874db65ae341580ed848452cb42c94ad3949e2..0d31e2018e1ee9ae80136e04929e1b9b2c9a9c67 100644 (file)
@@ -1273,3 +1273,40 @@ test!(test_with_example_twice {
                 execs().with_status(0));
     assert_that(&p.bin("examples/foo"), existing_file());
 });
+
+test!(example_with_dev_dep {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+
+            [lib]
+            name = "foo"
+            test = false
+            doctest = false
+
+            [dev-dependencies.a]
+            path = "a"
+        "#)
+        .file("src/lib.rs", "")
+        .file("examples/ex.rs", "extern crate a; fn main() {}")
+        .file("a/Cargo.toml", r#"
+            [package]
+            name = "a"
+            version = "0.0.1"
+            authors = []
+        "#)
+        .file("a/src/lib.rs", "");
+
+    assert_that(p.cargo_process("test").arg("-v"),
+                execs().with_status(0)
+                       .with_stdout(format!("\
+[..]
+[..]
+[..]
+[..]
+{running} `rustc [..] --crate-name ex [..] --extern a=[..]`
+", running = RUNNING).as_slice()));
+});